<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\mobilenode\model;

class RoleList extends \app\BaseModel
{
    protected $name = "massage_mobile_role_list";
    public function dataAdd($data)
    {
        $data["create_time"] = time();
        if(isset($data["node"])) {
            $node = $data["node"];
            unset($data["node"]);
        }
        $res = $this->insert($data);
        $id = $this->getLastInsID();
        if(isset($node)) {
            $this->updateSome($node, $id, $data["uniacid"]);
        }
        return $id;
    }
    public function updateSome($data, $id, $uniacid)
    {
        $node_model = new RoleNode();
        $node_model->where(["role_id" => $id])->delete();
        if(!empty($data)) {
            foreach ($data as $k => $v) {
                $data[$k]["uniacid"] = $uniacid;
                $data[$k]["role_id"] = $id;
                $data[$k]["auth"] = !empty($v["auth"]) ? implode(",", $v["auth"]) : "";
            }
            $node_model->saveAll($data);
        }
        return true;
    }
    public function dataUpdate($dis, $data)
    {
        if(isset($data["node"])) {
            $node = $data["node"];
            unset($data["node"]);
        }
        $res = $this->where($dis)->update($data);
        if(isset($node)) {
            $this->updateSome($node, $dis["id"], $data["uniacid"]);
        }
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("status desc,id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
    public function updateOne($id)
    {
        $user_id = $this->where(["id" => $id])->value("user_id");
        $res = $this->where(["user_id" => $user_id])->where("id", "<>", $id)->update(["status" => 0]);
        return $res;
    }
}

?>